﻿
////////////////////////////////////////////////////////////////////////////////////////////
// 文件名: ETL_Target_ViewConfigBLL.gen.cs
//
// 模块名称: TargetViewBll
//
// 作者: LPC
//
// 历史记录（记录修改记录，修改文件后请添加修改记录，注明修改时间、修改人，修改内容）:
// 13-3-14    LPC    创建文件
////////////////////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Text;
using Common;
using DAL;
using Model;

namespace BLL
{
    /// <summary>
    /// ETL_Target_ViewConfig表业务逻辑层
    /// </summary>
    public partial class ETL_Target_ViewConfigBLL : BaseBLL
    {
        public ETL_Target_ViewConfigBLL(LoginInfo info)
        {
            loginInfo = info;
        }
        const string ErrorCodeSelect = "";    //查询异常编码
        const string ErrorCodeInsert = "";    //添加异常编码
        const string ErrorCodeUpdate = "";    //修改异常编码
        const string ErrorCodeDelete = "";    //删除异常编码

        /// <summary>
        /// 根据GUID字段获取ETL_Target_ViewConfigInfo实体对象
        /// </summary>
        /// <param name="guid">GUID</param>
        /// <returns>ETL_Target_ViewConfigInfo实体对象</returns>
        public ETL_Target_ViewConfigInfo GetInfoById(string guid)
        {
            try
            {
                return new ETL_Target_ViewConfigDAL(loginInfo).GetInfoById(guid);
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_Target_ViewConfigBLL", "GetInfo", AppError.EROR, 0, ex, "获取TargetViewBll信息出错。",
                                String.Format("guid = {0}", guid));
                throw new SystemException(ErrorCodeSelect, ex);
            }
        }

        public void ETL_Target_ViewConfig_RollBack(string viewID, string targetSystemID)
        {
            new ETL_Target_ViewConfigDAL(loginInfo).ETL_Target_ViewConfig_RollBack(viewID, targetSystemID);
        }

        /// <summary>
        /// 往ETL_Target_ViewConfig表内添加新记录
        /// </summary>
        /// <param name="ETL_Target_ViewConfigInfo">ETL_Target_ViewConfigInfo实体对象</param>
        /// <returns>添加记录索引值</returns>
        public int Insert(ETL_Target_ViewConfigInfo eTLTargetViewConfigInfo)
        {
            try
            {
                int identity = new ETL_Target_ViewConfigDAL(loginInfo).Insert(eTLTargetViewConfigInfo);
                return identity;
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_Target_ViewConfigBLL", "Insert", AppError.EROR, 0, ex, "添加TargetViewBll信息出错。", null);
                throw new SystemException(ErrorCodeInsert, ex);
            }
        }
         

        /// <summary>
        /// 根据GUID字段获取ETL_Target_ViewConfigInfo实体对象
        /// </summary>
        /// <param name="guid">GUID</param>
        public void Delete(string guid)
        {
            try
            {
                new ETL_Target_ViewConfigDAL(loginInfo).Delete(guid);
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_Target_ViewConfigBLL", "Delete", AppError.EROR, 0, ex, "删除TargetViewBll信息出错。",
                                String.Format("guid = {0}", guid));
                throw new SystemException(ErrorCodeDelete, ex);
            }
        }

        public string GetMappingList(string tarviewID)
        {
            return new ETL_Target_ViewConfigDAL(loginInfo).GetMappingList(tarviewID);
        }

        public List<TableInfo> GetViewMappingData(string viewID)
        {
            return new ETL_Target_ViewConfigDAL(loginInfo).GetViewMappingData(viewID);
        }
        /// <summary>
        /// 根据GUID字段获取ETL_Target_ViewConfigInfo实体对象
        /// </summary>
        /// <param name="guid">GUID</param>
        /// <returns>List<ETL_Target_ViewConfigInfo>实体对象</returns>
        public List<ETL_Target_ViewConfigInfo> GetViewConfigList(IDataParameter[] par, string s, string o, out int totalCount)
        {
            try
            {
                totalCount = 0;
                return new ETL_Target_ViewConfigDAL(loginInfo).GetViewConfigList(par, s, o, out totalCount);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 根据GUID字段获取ETL_Target_ViewConfigInfo实体对象
        /// </summary>
        /// <param name="guid">GUID</param>
        /// <returns>List<ETL_Target_ViewConfigInfo>实体对象</returns>
        public int GetListCount(IDataParameter[] par)
        {
            try
            {
                return new ETL_Target_ViewConfigDAL(loginInfo).GetListCount(par);
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_Target_ViewConfigBLL", "GetInfo", AppError.EROR, 0, ex, "获取TargetViewBll信息出错。",
                                "");
                throw new SystemException(ErrorCodeSelect, ex);
            }
        }

        public List<ETL_Target_ViewConfigInfo> GetViewBySystemId(SqlParameter[] par)
        {
            try
            {
                return new ETL_Target_ViewConfigDAL(loginInfo).GetViewBySystemId(par);
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_Target_ViewConfigBLL", "GetInfo", AppError.EROR, 0, ex, "获取TargetViewBll信息出错。",
                                "");
                throw new SystemException(ErrorCodeSelect, ex);
            }
        }

        public List<TableInfo> GetSourceColumnList(SqlParameter[] par, string InIDs, string expIDs, string tarColID)
        {
            try
            {
                return new ETL_Target_ViewConfigDAL(loginInfo).GetSourceColumnList(par, InIDs, expIDs, tarColID);
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_Target_ViewConfigBLL", "GetInfo", AppError.EROR, 0, ex, "获取TargetViewBll信息出错。",
                                "");
                throw new SystemException(ErrorCodeSelect, ex);
            }
        }
        public DataTable GetTargetViewInfoByViewID(SqlParameter[] par)
        {
            return new ETL_Target_ViewConfigDAL(loginInfo).GetTargetViewInfoByViewID(par);
        }

        public ETL_Target_ViewConfigInfo Load(string targetSystemID, string mdp_ViewSchema, string mdp_ViewName)
        {
            return new ETL_Target_ViewConfigDAL(loginInfo).Load(targetSystemID, mdp_ViewSchema, mdp_ViewName);
        }

        public DataTable Load(string viewID)
        {
            return new ETL_Target_ViewConfigDAL(loginInfo).Load(viewID);
        }

        public int UpdateViewConfigScripts(string viewID, string targetSystemID, string viewName, int isConfigured)
        {
            return new ETL_Target_ViewConfigDAL(loginInfo).UpdateViewConfigScripts(viewID, targetSystemID, viewName, isConfigured);
        }

        public void InsertStep(ETLSYSJobConfigStep data)
        {
            new ETLSYSJobConfigStepDAL(loginInfo).Add(data);
        }

        public void InsertStepPredecessors(ETLSYSJobConfigStepPredecessors data)
        {
            new ETLSYSJobConfigStepPredecessorsDAL(loginInfo).Add(data);
        }

        public ETLSYSJobConfigStep LoadStep(string stepId)
        {
            return new ETLSYSJobConfigStepDAL(loginInfo).GetItemByStepID(stepId);
        }

        #region ETL_Source_ViewConfig

        public int Insert2(ETL_Target_ViewConfigInfo viewConfigInfo)
        {
            var result = 0;
            ETL_Target_ViewConfigDAL dal = new ETL_Target_ViewConfigDAL(loginInfo);
            result = dal.Insert2(viewConfigInfo);
            return result;
        }

        public ETL_Target_ViewConfigInfo GetTargetViewConfigInfoByGuid(string guid)
        {
            ETL_Target_ViewConfigDAL dal = new ETL_Target_ViewConfigDAL(loginInfo);
            return dal.GetTargetViewConfigInfoByGuid(guid);
        }

        public string BigDataTagValue(string guid)
        {
            ETL_Target_ViewConfigDAL dal = new ETL_Target_ViewConfigDAL(loginInfo);
            return dal.BigDataTagValue(guid);
        }
        public bool UpdateConfigStatus(string guid)
        {
            ETL_Target_ViewConfigDAL dal = new ETL_Target_ViewConfigDAL(loginInfo);
            return dal.UpdateConfigStatus(guid);
        }

        public int Update(ETL_Target_ViewConfigInfo viewConfigInfo)
        {
            ETL_Target_ViewConfigDAL dal = new ETL_Target_ViewConfigDAL(loginInfo);
            return dal.Update(viewConfigInfo);
        }

        public int Delete2(string viewID)
        {
            ETL_Target_ViewConfigDAL dal = new ETL_Target_ViewConfigDAL(loginInfo);
            return dal.Delete2(viewID);
        }


        public List<ETL_Target_ViewConfigInfo> GetViewConfigById(string targetSystemID, string orderBy, bool asc, int pageIndex, int pageSize, out int recordCount)
        {
            ETL_Target_ViewConfigDAL dal = new ETL_Target_ViewConfigDAL(loginInfo);
            var list = dal.GetViewConfigById(targetSystemID, orderBy, asc, pageIndex, pageSize, out  recordCount);
             
            return list;
        }
        public List<ETL_Target_ViewConfigInfo> GetViewConfigById(string targetSystemID)
        {
            ETL_Target_ViewConfigDAL dal = new ETL_Target_ViewConfigDAL(loginInfo);
            var list = dal.GetViewConfigById(targetSystemID);

            return list;
        }

        public List<ETL_Target_ViewConfigInfo> GetAllViewConfigById(List<SqlParameter> para, string ExtIDs, string sort, string order, out int recordCount)
        {
            ETL_Target_ViewConfigDAL dal = new ETL_Target_ViewConfigDAL(loginInfo);
            var list = dal.GetAllViewConfigById(para,ExtIDs, sort, order, out  recordCount);

            return list;
        }
        public List<ETL_Target_ViewConfigInfo> GetViewConfigBySysIdANDNotForGroup(string targetSystemID)
        {
            ETL_Target_ViewConfigDAL dal = new ETL_Target_ViewConfigDAL(loginInfo);
            var list = dal.GetViewConfigBySysIdANDNotForGroup(targetSystemID);
            return list;
        }

        public List<ETL_Target_ViewConfigInfo> GetViewConfigBySysIdANDGroupID(string targetSystemID, string groupID,int rows,int page)
        {
            ETL_Target_ViewConfigDAL dal = new ETL_Target_ViewConfigDAL(loginInfo);
            var list = dal.GetViewConfigBySysIdANDGroupID(targetSystemID, groupID,rows,page);
            return list;
        }

        public int AddModelsToGroup(List<string> viewIDs, string groupID)
        {
            var result = 0;
            ETL_Target_ViewConfigDAL dal = new ETL_Target_ViewConfigDAL(loginInfo);
            foreach (var viewID in viewIDs)
            {
                result += dal.AddModelToGroup(viewID, groupID);
            }
            return result;
        }

        public int UpdatePushName(string viewID, string schema, string pushName)
        {
            var result = 0;
            ETL_Target_ViewConfigDAL dal = new ETL_Target_ViewConfigDAL(loginInfo);
            result = dal.UpdatePushName(viewID, schema, pushName);
            return result;
        }

        public int RemoveModelFromGroup(string viewID)
        {
            var result = 0;
            ETL_Target_ViewConfigDAL dal = new ETL_Target_ViewConfigDAL(loginInfo);
            result = dal.RemoveModelFromGroup(viewID);
            return result;
        }
        #endregion


        #region 读取模型数据

        public DataTable GetModelTableData(string tableName, string columns
            , string orderBy, bool asc
             , int recordCount)
        {
            ETL_Target_ViewConfigDAL dal = new ETL_Target_ViewConfigDAL(loginInfo);
            return dal.GetModelTableData(tableName, columns
            , orderBy, asc
             , recordCount);
        }

        public DataTable GetModelTableData(string viewID, string type, string order, string sort, string[] sql, IDataParameter[] sqlPara)
        {
            ETL_Target_ViewConfigDAL dal = new ETL_Target_ViewConfigDAL(loginInfo);
            return dal.GetModelTableData(viewID, type,order, sort, sql, sqlPara);
        }
        #endregion

        #region 导出建表语句

        public string GetCreateTbScript(string viewID, string etlType, int dbType)
        {
            ETL_Target_ViewConfigDAL dal = new ETL_Target_ViewConfigDAL(loginInfo);
            return dal.GetCreateTbScript(viewID, etlType, dbType);
        }
        #endregion

    }
}